package tests;

import junit.framework.Assert;

import org.junit.Before;
import org.junit.Test;

import exceptions.InvalidLogin;
import exceptions.InvalidSession;
import exceptions.SessionDoesNotExist;
import exceptions.UserNotExistsException;

import root.Session;
import root.SessionManager;
import root.user.UserManager;


public class TestSessionManager {
	final private String username = "dan";
	String id1, id2;
	SessionManager ssManager;
	@Before
	public void setUp(){
		try {
			UserManager.getUserManager().createUser(username, "oi", "ola");
		}catch (Exception ex){
		
		}
		ssManager = SessionManager.getSessionManager();
	}
	
	@Test(expected=InvalidLogin.class)
	public void createInvalidSessionNullString() throws InvalidLogin, UserNotExistsException {
		ssManager.createSession(null);
	}
	@Test(expected=InvalidLogin.class)
	public void createInvalidSessionEMPTYString() throws InvalidLogin, UserNotExistsException {
		ssManager.createSession("");
	}
	@Test(expected=InvalidSession.class)
	public void invalidIDString() throws SessionDoesNotExist, InvalidSession {
		ssManager.getSession(null);
	}
	
	@Test
	public void testAddSession() throws SessionDoesNotExist, InvalidSession, InvalidLogin, UserNotExistsException {
		id1 = ssManager.createSession(username);
		Assert.assertEquals(username, ssManager.getSession(id1).getLogin());
		
	}
	
	@Test(expected=SessionDoesNotExist.class)
	public void testKillSession() throws SessionDoesNotExist, InvalidSession, InvalidLogin, UserNotExistsException {
		id1 = ssManager.createSession(username);
		ssManager.killSession(id1);
		ssManager.getSession(id1);	
	}
	
	
	
}
